package com.l024.framework.view;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.l024.framework.R;
import com.l024.framework.manager.DialogManager;
import com.l024.framework.utils.AnimUtils;

/**
 * @author wu_ming_zhi_bei
 * @date 2020/2/26 11:40
 * @Notes 加载提示款
 */
public class LodingView {
    private DialogView mDialogView;
    private ImageView iv_loding;
    private TextView tv_loding_text;
    private ObjectAnimator mAnim;


    public LodingView(Context mContext) {
        mDialogView = DialogManager.getInstance().initView(mContext, R.layout.dialog_loding);
        iv_loding = mDialogView.findViewById(R.id.iv_loding);
        tv_loding_text = mDialogView.findViewById(R.id.tv_loding_text);
        mAnim = AnimUtils.rotation(iv_loding);
    }

    /**
     * 设置加载的文字
     * @param text
     */
    public void setLodingText(String text){
        if(!TextUtils.isEmpty(text)){
            tv_loding_text.setText(text);
        }
    }

    /**
     * 显示
     */
    public void  show(){
        mAnim.start();
        DialogManager.getInstance().show(mDialogView);
    }
    /**
     * 显示
     */
    public void  show(String text){
        mAnim.start();
        setLodingText(text);
        DialogManager.getInstance().show(mDialogView);
    }
    /**
     * 隐藏
     */
    public void hide(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            mAnim.pause();
        }
        DialogManager.getInstance().hide(mDialogView);
    }
}
